﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SudokuValidator
{
    public class Puzzle
    {
        private int[,] myArray;

        public Puzzle()
        {
            myArray = new int[9, 9];        
        }

        public Puzzle(int[,] array)
        {
            myArray = array;
        }

        public Puzzle(int[][] array)
        {
            myArray = new int[9, 9];
            for(int i = 0; i < 9 ; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    myArray[i, j] = array[i][j];
                }
            }
        }

        public int[] GetRow(int index)
        {
            int[] rowArray = new int[9];
            if (index < 0)
            {
                for (int i = 0; i < 9; i++)
                {
                    rowArray[i] = myArray[0, i];
                }
                return rowArray;
            }
            else if (index > 8)
            {
                for (int i = 0; i < 9; i++)
                {
                    rowArray[i] = myArray[8, i];
                }
                return rowArray;
            }
            else
            {
                for (int i = 0; i < 9; i++)
                {
                    rowArray[i] = myArray[index, i];
                }
                return rowArray;
            }
        }

        public int GetIndex(int i, int j)
        {
            return myArray[i,j];
        }

        public int[] GetBox(int i)
        {
            int[] row = new int[9];
            if (i <= 0)
            {
                row = new int[9] { myArray[0, 0], myArray[0, 1], myArray[0, 2], myArray[1, 0], myArray[1, 1], myArray[1, 2], myArray[2, 0], myArray[2, 1], myArray[2, 2] }; 
            }
            else if (i == 1)
            {
                row = new int[9] { myArray[0, 3], myArray[0, 4], myArray[0, 5], myArray[1, 3], myArray[1, 4], myArray[1, 5], myArray[2, 3], myArray[2,4], myArray[2, 5] }; 
            }
            else if (i == 2)
            {
                row = new int[9] { myArray[0, 6], myArray[0, 7], myArray[0, 8], myArray[1, 6], myArray[1, 7], myArray[1, 8], myArray[2, 6], myArray[2, 7], myArray[2, 8] };
            }
            else if (i == 3)
            {
                row = new int[9] { myArray[3, 0], myArray[3, 1], myArray[3, 2], myArray[4, 0], myArray[4, 1], myArray[4, 2], myArray[5, 0], myArray[5, 1], myArray[5, 2] };
            }
            else if (i == 4)
            {
                row = new int[9] { myArray[3, 3], myArray[3, 4], myArray[3, 5], myArray[4, 3], myArray[4, 4], myArray[4, 5], myArray[5, 3], myArray[5, 4], myArray[5, 5] };
            }
            else if (i == 5)
            {
                row = new int[9] { myArray[3, 6], myArray[3, 7], myArray[3, 8], myArray[4, 6], myArray[4, 7], myArray[4, 8], myArray[5, 6], myArray[5, 7], myArray[5, 8] };
            }
            else if (i == 6)
            {
                row = new int[9] { myArray[6, 0], myArray[6, 1], myArray[6, 2], myArray[7, 0], myArray[7, 1], myArray[7, 2], myArray[8, 0], myArray[8, 1], myArray[8, 2] };
            }
            else if (i == 7)
            {
                row = new int[9] { myArray[6, 3], myArray[6, 4], myArray[6, 5], myArray[7, 3], myArray[7, 4], myArray[7, 5], myArray[8, 3], myArray[8, 4], myArray[8, 5] };
            }
            else if (i >= 8)
            {
                row = new int[9] { myArray[6, 6], myArray[6, 7], myArray[6, 8], myArray[7, 6], myArray[7, 7], myArray[7, 8], myArray[8, 6], myArray[8, 7], myArray[8, 8] };
            }
            return row;
        }

        public int[] GetColumn(int index)
        {
            int[] rowArray = new int[9];
            if (index < 0)
            {
                for (int i = 0; i < 9; i++)
                {
                    rowArray[i] = myArray[i, 0];
                }
                return rowArray;
            }
            else if (index > 8)
            {
                for (int i = 0; i < 9; i++)
                {
                    rowArray[i] = myArray[i, 8];
                }
                return rowArray;
            }
            else
            {
                for (int i = 0; i < 9; i++)
                {
                    rowArray[i] = myArray[i, index];
                }
                return rowArray;
            }
        }

    }
}
